/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						 adventure_sounds.h

	$Header: /heroes4/adventure_sounds.h $

	$NoKeywords: $

 ************************************************************************/

#if !defined( ADVENTURE_SOUNDS_H_INCLUDED )
#define ADVENTURE_SOUNDS_H_INCLUDED

#include "map_point.h"
#include "music.h"
#include "playing_sound.h"
#include "playing_sound_ptr.h"
#include "sound.h"
#include "sound_cache.h"

class t_adventure_object;
class t_adventure_map;
class t_creature_stack;
class t_qualified_adv_object_type;


enum t_adventure_sound_type
{
	k_adventure_sound_none = -1,

	k_adventure_sound_town_build,
	k_adventure_sound_dig,
	k_adventure_sound_flag_mine,
	k_adventure_sound_pickup_1,
	k_adventure_sound_pickup_2,
	k_adventure_sound_pickup_3,
	k_adventure_sound_pickup_4,
	k_adventure_sound_pickup_5,
	k_adventure_sound_pickup_6,
	k_adventure_sound_teleport_in,
	k_adventure_sound_teleport_out,

	k_adventure_sound_count
};

enum t_dialog_sound_type
{
	k_dialog_sound_none = -1,

	k_dialog_sound_abandoned,
	k_dialog_sound_artifact,
	k_dialog_sound_creature_bank,
	k_dialog_sound_experience,
	k_dialog_sound_kingdom_overview,
	k_dialog_sound_level_up,
	k_dialog_sound_luck,
	k_dialog_sound_magi,
	k_dialog_sound_mana,
	k_dialog_sound_marketplace,
	k_dialog_sound_military,
	k_dialog_sound_morale,
	k_dialog_sound_new_class,
	k_dialog_sound_new_month,
	k_dialog_sound_portal,
	k_dialog_sound_power_up,
	k_dialog_sound_puzzle,
	k_dialog_sound_quest,
	k_dialog_sound_recruit,
	k_dialog_sound_sanctuary,
	k_dialog_sound_sign,
	k_dialog_sound_shipyard,
	k_dialog_sound_shrine,
	k_dialog_sound_stables,
	k_dialog_sound_tavern,
	k_dialog_sound_thieves_guild,
	k_dialog_sound_tower,
	k_dialog_sound_treasure,
	k_dialog_sound_treasure_chest,
	k_dialog_sound_university,
	k_dialog_sound_view_world,
	k_dialog_sound_button,
	k_dialog_sound_enter_combat,

	k_dialog_sound_count
};

// ---------------------------------------------
// class used to hold playing sound and it's 
// adventure map position
// ---------------------------------------------
class t_managed_sound : public t_counted_object
{
public:
	t_managed_sound(	t_adventure_object const & owner, 
						t_level_map_point_2d const & point, 
						t_playing_sound_ptr playing_sound_ptr );
	inline int						get_former_volume() const;
	t_adventure_object const &		get_owner() const;
	inline void						set_former_volume(int);
	t_level_map_point_2d const &	get_position() const;
	t_playing_sound_ptr				get_sound_ptr();
	void							set_owner_id();
	void							set_position( t_level_map_point_2d const & point );
protected:
	t_adventure_object const &		m_owner;
	t_level_map_point_2d			m_point;
	t_playing_sound_ptr				m_sound_ptr;
	int								m_former_volume;
};

// managed sound pointer type
typedef t_counted_ptr<t_managed_sound> t_managed_sound_ptr;

// ---------------------------------------------
// managed sound constructor
// ---------------------------------------------
inline t_managed_sound::t_managed_sound(	t_adventure_object const & owner,
									t_level_map_point_2d const & point, 
									t_playing_sound_ptr playing_sound_ptr )
									: m_owner( owner )
{
	m_point		= point;
	m_sound_ptr = playing_sound_ptr;
}

inline void t_managed_sound::set_former_volume(int volume)
{
	m_former_volume = volume;
}

inline int t_managed_sound::get_former_volume() const
{
	return m_former_volume;
}

// ---------------------------------------------
// get the owner id of a playing sound
// ---------------------------------------------
inline t_adventure_object const & t_managed_sound::get_owner() const
{
	return m_owner;
}

// ---------------------------------------------
// managed sound constructor
// ---------------------------------------------
inline t_level_map_point_2d const &	t_managed_sound::get_position() const
{
	return m_point;
}

// ---------------------------------------------
// managed sound constructor
// ---------------------------------------------
inline t_playing_sound_ptr t_managed_sound::get_sound_ptr()
{
	return m_sound_ptr;
}

// ---------------------------------------------
// set managed sound position
// ---------------------------------------------
inline void t_managed_sound::set_position( t_level_map_point_2d const & point )
{
	m_point = point;
}

void stop_owner_sound(const t_adventure_object * owner);
t_sound_ptr get_adventure_sound( t_adventure_sound_type type );
t_sound_ptr get_adventure_sound( t_qualified_adv_object_type const& type );
t_managed_sound_ptr play_adventure_sound(	t_adventure_object const & owner,
											t_sound_ptr sound, 
											t_level_map_point_2d const & point, 
											int volume, bool fade_in = false );
void handle_adventure_sound_minimization(bool minimized);
void close_active_sounds();
void update_active_sounds( t_level_map_point_2d point, t_adventure_map const& map );
int update_sound( t_level_map_point_2d point, t_managed_sound * playing_sound, bool initing_volume = false );
t_sound_ptr get_dialog_sound( t_dialog_sound_type type );

#endif // ADVENTURE_SOUNDS_H_INCLUDED